# -*- encoding:utf-8 -*-
# @Time : 2020/11/24 10:00 
# @Author : ZHH
"""
products =   [[“iphone”,6888],[“MacPro”,14800],[“小米6”,2499],[“Coffee”,31],[“Book”,60],[“Nike”,699]]
a、打印出以下格式
b、
购物车功能：根据的products列表写一个循环不断询问用户想买什么，用户选择一个商品编号，就把对应的商品添加到购物车里，最终用户输入q退出时，打印购买的商品列表。
提示:有shop_car和shop_cost 两个列表，当时输入商品不存在的时候，提示相关错误
"""

from collections import defaultdict

products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499], ["Coffee", 31], ["Book", 60], ["Nike", 699]]
shop_cost = {}
shop_car = defaultdict(int)
count_ = 0
total_cost = 0
print("-"*6,"商品列表","-"*6)
for i in products:
    print(i[0], '\t', i[1])
    shop_cost[i[0]] = i[1]

while True:
    input_ = input('输入：')
    if input_ == 'q':
        shop_car = dict(shop_car)
        if shop_car:
            for k, v in shop_car.items():
                count_cost = shop_cost[k] * v
                print(f"{k}：{v}个,价格：{count_cost}")
                count_ += v
                total_cost += count_cost
            print(f"总计：{count_}个,价格：{total_cost}")
        break
    if input_ not in shop_cost:
        print('没有')
    else:
        shop_car[input_] += 1
# 1 少个退出的提示
# 2 少个购买成功的提示